package com.three.iot.rest.controller.admin;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import com.three.iot.api.ProductService;
import com.three.iot.commons.dto.ProductCondDto;
import com.three.iot.commons.dto.ProductResultDto;
import com.three.iot.commons.enums.Result;
import com.three.iot.commons.enums.ResultCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author luiz
 * @Title: DeviceController
 * @ProjectName iot-server
 * @Description: TODO
 * @date 2019-05-14 14:45
 */
@RestController
@RequestMapping("/admin/product")
@Api(tags = "产品信息api")
public class ProductController {
    private static final Logger logger = LoggerFactory.getLogger(ProductController.class);
    @Resource
    private ProductService productService;

    /**
     * 产品分页查询
     */
    @PostMapping("/listPage")
    @ApiOperation(value = "产品分页查询", notes = "产品分页查询")
    public Result findPage(@RequestBody ProductCondDto prodCondDto) {
        try {
            Page<ProductResultDto> prodRespDtoPage = productService.listPage(prodCondDto);
            PageInfo pageInfo = new PageInfo(prodRespDtoPage);
            return Result.newSuccess(pageInfo);
        } catch (Exception e) {
            logger.error("产品分页查询失败:{}", e);
            return Result.newError(ResultCode.FAIL);
        }
    }


}
